package com.cyt.sys.util;

import com.cyt.base.util.StringUtils;

import java.util.Arrays;

/**
 * @author taocongcong
 * @create 2019-03-13 10:55
 */
public class NamingUtil {

    public static String underlineToCamel(String name) {
        if(StringUtils.isEmpty(name)) {
            return "";
        } else {
            String tempName = name;
            if(StringUtils.isCapitalMode(name) || StringUtils.isMixedMode(name)) {
                tempName = name.toLowerCase();
            }

            StringBuilder result = new StringBuilder();
            String[] camels = tempName.split("_");
            Arrays.stream(camels).filter((camel) -> {
                return !StringUtils.isEmpty(camel);
            }).forEach((camel) -> {
                if(result.length() == 0) {
                    result.append(camel);
                } else {
                    result.append(capitalFirst(camel));
                }

            });
            return result.toString();
        }
    }

    public static String capitalFirst(String name) {
        return StringUtils.isNotEmpty(name)?name.substring(0, 1).toUpperCase() + name.substring(1):"";
    }
}
